<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core" >
<f:view>
<h:head>
    <title>Online Shop</title>
</h:head>
<h:body>
    <c:set value="0" var="total" scope="view" />
<h:form>
<table border="1" width="550" rules="none" cellspacing="0" cellpadding="0" >
   <tr height="50"><td colspan="5" align="center">购买的商品如下</td></tr>
   <tr align="center" height="30" bgcolor="lightgrey">
         <td></td>
	 <td width="25%">名称</td>
	 <td>价格(元/斤)</td>
	 <td>数量</td>
	 <td>总价(元)</td>
	 <td>移除(-1/次)</td>
    </tr>
    <c:choose>
        <c:when test="#{empty(myCar.buylist)}">
    <tr height="100"><td colspan="5" align="center">您的购物车为空！</td></tr>
        </c:when>
        <c:otherwise>
        <c:forEach var="single" items="#{myCar.buylist}">          
        <tr align="center" height="50">
         <td><h:graphicImage library="img" name="#{single.img}" title="#{single.name}" /></td>
         <td>${single.name}</td>
         <td>#{single.price}</td>
         <td>#{single.num}</td>
         <c:set var="money" value="#{single.price*single.num}"/>
         <td><h:outputText  value="#{money}">
               <f:convertNumber pattern="#0.00" />  
             </h:outputText>
         </td>
         <td><h:commandLink action="#{myCar.removeItem(single.id)}" value="移除">
             </h:commandLink>
         </td>
       </tr>
       <c:set var="total" value="#{total+money}"/>
       </c:forEach>
    </c:otherwise>
   </c:choose>
   <tr height="50" align="center">
       <td colspan="5">应付金额:
           <h:outputFormat value="#{total}" >
               <f:convertNumber pattern="#0.00" />
           </h:outputFormat>
       </td>
   </tr>
   <tr height="50" align="center">
	<td colspan="2"><a href="show.xhtml">继续购物</a></td>
        <td colspan="3"><h:commandLink action="#{myCar.clearCar}" value="清空购物车"/>
        </td>
   </tr>
</table>
</h:form>
</h:body>
</f:view>
</html>


